USE [OctoNetApps]
GO

/****** Object:  StoredProcedure [classified].[ClassifiedAds_Delete]    Script Date: 05/25/2011 06:54:24 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [classified].[ClassifiedAds_Delete]
	@ResourceID bigint,
	@AdID bigint
AS
BEGIN

	SET NOCOUNT ON;
		
		BEGIN TRY
	
		BEGIN TRANSACTION TR
		
		INSERT INTO classified.ExpiredClassifiedAds
		SELECT [AdID]
			  ,[ResourceID]
			  ,[CategoryID]
			  ,[PostTime]
			  ,DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))
			  ,[Searching]
			  ,[Title]
			  ,[AdText]
			  ,[TextFormat]
			  ,[Location]
			  ,[PriceType]
			  ,[Price]
			  ,[UserID]
			  ,[UserComputerID]
			  ,[UserIP]
			  FROM classified.ClassifiedAds WHERE ResourceID = @ResourceID AND AdID = @AdID
			  
		DELETE FROM classified.ClassifiedAds WHERE ResourceID = @ResourceID AND AdID = @AdID
		
		COMMIT TRANSACTION TR
    END TRY
    BEGIN CATCH
		ROLLBACK TRANSACTION TR
    END CATCH
END






GO


